<?php
/**
 * @Author: Xu Liu email:2867557054@qq.com
 * @Date:   2017-03-06 14:41:35
 * @Last Modified by:   Xu Liu
 * @Last Modified time: 2018-03-16 14:59:39
 */
if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
class BaseXf
{
    protected function _paihang()
    {
        global $_G;
        return C::t('#jameson_read#jamesonread_books')->fetch_paihang();
    }
    protected function _tuijian()
    {
        global $_G;
        return C::t('#jameson_read#jamesonread_books')->fetch_tuijian();
    }
    protected function _json($data = array())
    {
        header('Content-Type: application/json; charset=utf-8');
        echo json_encode($this->trans($data));
        exit;
    }
    protected function trans($value)
    {
        if (is_array($value)) {
            foreach ($value as $key1 => $value1) {
                if (is_array($value1)) {
                    $value[$key1] = $this->trans($value1);
                } else {
                    if (!$this->is_utf8($value[$key1])) {
                        $value[$key1] = diconv($value[$key1], CHARSET, 'utf-8');
                    }
                }
            }
            return $value;
        } else {
            if ($this->is_utf8($value)) {
                return $value;
            } else {
                return diconv($value, CHARSET, 'utf-8');
            }
        }
    }
    protected function arr_sort($array, $key, $order = "asc")
    {
        $arr_nums = $arr = array();
        foreach ($array as $k => $v) {
            $arr_nums[$k] = $v[$key];
        }
        if ($order == 'asc') {
            asort($arr_nums);
        } else {
            arsort($arr_nums);
        }
        foreach ($arr_nums as $k => $v) {
            $arr[$k] = $array[$k];
        }
        return $arr;
    }

    public function fxact($fxuid, $tid, $book_id, $jiangli, $trameid, $ip)
    {
        return fxact($fxuid, $tid, $book_id, $jiangli, $trameid, $ip);
    }
    // 阅读记录
    public function history($cookiekey)
    {
        if ($history = getcookie($cookiekey)) {
            $history      = unserialize($history);
            $historybooks = array();
            if($history){
            foreach ($history as $key => $value) {
                if ($value) {
                    $tmp = explode(',', $value);
                    $historybooks[$tmp[0]]['book_id'] = $tmp[0];
                    $historybooks[$tmp[0]]['tid'] = $tmp[1];
                    $historybooks[$tmp[0]]['pid'] = $tmp[2];
                    $historybooks[$tmp[0]]['subject'] = $tmp[3];
                    $historybooks[$tmp[0]]['book_name'] = $tmp[4];
                    $historybooks[$tmp[0]]['image'] = $tmp[5];
                }
            }
            return $historybooks;
            }
        } 
        return array();
    }
    // 购买操作
    public function buy()
    {
        global $_G;
        if(FORMHASH != $_GET['formhash']){
            showmessage(lang('plugin/jameson_read', 'laiyuanfeifa'), dreferer());
        }
        if (!$_G['uid']) {
            showmessage(lang('plugin/jameson_read', 'bixudenglu'), null, array(), array('showmsg' => true, 'login' => 1));
        }
        $book_id  = intval($_GET['book_id']);
        $bookinfo = C::t('#jameson_read#jamesonread_books')->fetch($book_id);
        if (!$book_id || !$bookinfo) {
            showmessage(lang('plugin/jameson_read', 'goumaichucuo'), dreferer());
        } elseif(DB::result_first('SELECT COUNT(id) FROM %t WHERE buy_id=%d AND book_id=%d',array('jamesonread_buybooks',$_G['uid'],$book_id))){
            showmessage(lang('plugin/jameson_read', 'yijinggoumaiguo'), dreferer());
        } else {
            if ($_G['jameson_read']['tramenum'] < $bookinfo['bookmoney']) {
                $dizhi = '';
                if (checkmobile()) {
                    $dizhi = $_G['jameson_read']['sjchongzhi'] ? $_G['jameson_read']['sjchongzhi'] : $dizhi;
                } else {
                    $dizhi = $_G['jameson_read']['pcchongzhi'] ? $_G['jameson_read']['pcchongzhi'] : $dizhi;
                }
                showmessage($dizhi?($_G['jameson_read']['trametitle'] . lang('plugin/jameson_read', 'buzuqingchongzhi')):lang('plugin/jameson_read','buzhichishoujiduan'), $dizhi);
            } else {
                // 待插入buybooks 数据
                $data                = array();
                $data['buy_id']      = $_G['uid'];
                $data['author_id']   = (int) $bookinfo['uid'];
                $data['category_id'] = (int) $bookinfo['category_id'];
                $data['book_id']     = $book_id;
                $data['price']       = (int) $bookinfo['bookmoney'];
                $data['addtime']     = TIMESTAMP;
                // 计算佣金
                $yongjin = floor($data['price'] * ($_G['jameson_read']['yongjin']/ 100));
                // 购买者减去 bookmoney
                $res1 = updatemembercount($_G['uid'],
                    array($_G['jameson_read']['trameid'] => -$data['price']),
                    true, 'jgm', 0, lang('plugin/jameson_read', 'goumaitushufeiyong'), daddslashes($bookinfo['book_name']));
                // 作者增加 bookmoney-yongji
                $res2 = updatemembercount($data['author_id'],
                    array($_G['jameson_read']['trameid'] => ($data['price'] - $yongjin)),
                    true, 'jxs', 0, lang('plugin/jameson_read', 'xiaoshoutushufeiyong'), daddslashes($bookinfo['book_name']));
                // admin增加 yongji
                if($yongjin>0){
                    $res3 = updatemembercount(1,
                    array($_G['jameson_read']['trameid'] => $yongjin),
                    true, 'Y_J', 0, lang('plugin/jameson_read', 'xiaoshouyongjin'), daddslashes($bookinfo['book_name']));
                }
                if (!($res1 || $res2)) {
                    C::t('#jameson_read#jamesonread_buybooks')->insert($data);
                    C::t('#jameson_read#jamesonread_yongjin')->insert(array(
                        'buy_id'    => $_G['uid'],
                        'author_id' => $data['author_id'],
                        'book_id'   => $data['book_id'],
                        'saleprice' => $data['price'],
                        'yongjinbi' => $_G['jameson_read']['yongjin'],
                        'yongjin'   => $yongjin,
                        'addtime'   => TIMESTAMP,
                        'type'      => 1,
                    ));
                    $sendauthor = '<a href="./home.php?mod=space&uid='
                    . $_G['uid']
                    . '">'
                    . $_G['member']['username']
                    . '</a>'
                    . lang('plugin/jameson_read', 'goumailenidetushu')
                    . '<a href="'
                    . ($_G['cache']['plugin']['jameson_read']['rewurl'] ? jamesonurl('book', $data['book_id']) : './plugin.php?id=jameson_read&contrl=index&act=book&book_id=' . $data['book_id'])
                    . '">['
                    . $bookinfo['book_name']
                    . ']</a>,'
                    . lang('plugin/jameson_read', 'kouchuyongjinhoushouru')
                        . ($data['price'] - $yongjin)
                        . $_G['jameson_read']['trametitle'];

                    $sendbuy =
                    lang('plugin/jameson_read', 'nichenggonggoumaitushu')
                    . '<a href="'
                    . ($_G['cache']['plugin']['jameson_read']['rewurl'] ? jamesonurl('book', $data['book_id']) : './plugin.php?id=jameson_read&contrl=index&act=book&book_id=' . $data['book_id'])
                    . '">['
                    . $bookinfo['book_name']
                    . ']</a>,'
                    . lang('plugin/jameson_read', 'yikouchu')
                        . $data['price']
                        . $_G['jameson_read']['trametitle'];
                    // 向作者发送消息
                    jameson_sendsms($data['author_id'], 0, '', $sendauthor, $data['book_id']);
                    // 向购买者发送消息
                    jameson_sendsms($_G['uid'], 0, '', $sendbuy, $data['book_id']);
                    header('Cache-control:no-cache,no-store,must-revalidate');
                    header('Pragma:no-cache');
                    header('Expires:0');
                    showmessage(lang('plugin/jameson_read', 'goumaichenggong'), dreferer());
                } else {
                    showmessage(lang('plugin/jameson_read', 'goumaichucuo'), dreferer());
                }
            }
        }
    }
    public function buytids()
    {
        global $_G;
        if(FORMHASH != $_GET['formhash']){
            showmessage(lang('plugin/jameson_read', 'laiyuanfeifa'), dreferer());
        }
        if (!$_G['uid']) {
            showmessage(lang('plugin/jameson_read', 'bixudenglu'), null, array(), array('showmsg' => true, 'login' => 1));
        }
        $tid = intval($_GET['tid']);
        if (!$tid || !($columinfo = DB::fetch_first('SELECT * FROM %t WHERE tid=%d', array('jamesonread_colums', $tid)))) {
            showmessage(lang('plugin/jameson_read', 'goumaichucuo'), dreferer());
        } else {
            if($_GET['autobuy']){
                dsetcookie('jamesonreadautobuy_'.$_G['uid'],1, 4800 * 3600);
            }
            if ($_G['jameson_read']['tramenum'] < $columinfo['price']) {
                $dizhi = '';
                if (checkmobile()) {
                    $dizhi = $_G['jameson_read']['sjchongzhi'] ? $_G['jameson_read']['sjchongzhi'] : $dizhi;
                } else {
                    $dizhi = $_G['jameson_read']['pcchongzhi'] ? $_G['jameson_read']['pcchongzhi'] : $dizhi;
                }
                showmessage($dizhi?($_G['jameson_read']['trametitle'] . lang('plugin/jameson_read', 'buzuqingchongzhi')):lang('plugin/jameson_read','buzhichishoujiduan'), $dizhi);
            } else {
                if (!C::t('#jameson_read#jamesonread_buytids')->sellaction($_G['uid'], $columinfo['uid'], $columinfo['price'], $tid, $columinfo['book_id'], $columinfo['category_id'], $_G['jameson_read']['trameid'], $_G['jameson_read']['yongjin'])) {
                    showmessage(lang('plugin/jameson_read', 'kouchushibai'), null);
                } else {
                    $yongjin       = floor($columinfo['price'] * ($_G['jameson_read']['yongjin']/ 100) );
                    $koufeimessage = lang('plugin/jameson_read', 'goumaichenggong') . ',' . lang('plugin/jameson_read', 'yikouchu') . $columinfo['price'] . $_G['jameson_read']['trametitle'];
                    $sendauthor    = '<a href="./home.php?mod=space&uid='
                    . $_G['uid']
                    . '">'
                    . $_G['member']['username']
                    . '</a>'
                    . lang('plugin/jameson_read', 'goumailenidetushu')
                    . lang('plugin/jameson_read', 'zhangjie')
                    . '<a href="'
                    . ($_G['cache']['plugin']['jameson_read']['rewurl'] ? jamesonurl('thread', $columinfo['tid'], $columinfo['pid']) : './plugin.php?id=jameson_read&contrl=index&act=read&tid=' . $columinfo['tid'] . '&pid=' . $columinfo['pid'])
                    . '">['
                    . $columinfo['subject']
                    . ']</a>,'
                    . lang('plugin/jameson_read', 'kouchuyongjinhoushouru')
                        . ($columinfo['price'] - $yongjin)
                        . $_G['jameson_read']['trametitle'];

                    $sendbuy =
                    lang('plugin/jameson_read', 'nichenggonggoumaizhangjie')
                    . '<a href="'
                    . ($_G['cache']['plugin']['jameson_read']['rewurl'] ? jamesonurl('thread', $columinfo['tid'], $columinfo['pid']) : './plugin.php?id=jameson_read&contrl=index&act=read&tid=' . $columinfo['tid'] . '&pid=' . $columinfo['pid'])
                    . '">['
                    . $columinfo['subject']
                    . ']</a>,'
                    . lang('plugin/jameson_read', 'yikouchu')
                        . $columinfo['price']
                        . $_G['jameson_read']['trametitle'];
                    // 向作者发送消息
                    jameson_sendsms($columinfo['uid'], 0, '', $sendauthor, $columinfo['colum_id']);
                    // 向购买者发送消息
                    jameson_sendsms($_G['uid'], 0, '', $sendbuy, $columinfo['colum_id']);
                    header('Cache-control:no-cache,no-store,must-revalidate');
                    header('Pragma:no-cache');
                    header('Expires:0');
                    showmessage($koufeimessage, dreferer(), array(), array('showmsg' => true, 'alert' => 'right'));
                }
            }
        }
    }
    // 通过ajax方式防止重复返回提交
    public function buytidsajax()
    {
        global $_G;
        if(FORMHASH != $_GET['formhash']){
            echo lang('plugin/jameson_read', 'laiyuanfeifa');
        }
        if (!$_G['uid']) {
            echo lang('plugin/jameson_read', 'bixudenglu');
        }
        $tid = intval($_GET['tid']);
        if (!$tid || !($columinfo = DB::fetch_first('SELECT * FROM %t WHERE tid=%d', array('jamesonread_colums', $tid)))) {
            echo lang('plugin/jameson_read', 'goumaichucuo');
        }else if(DB::result_first('SELECT count(id) FROM %t WHERE buy_id=%d AND tid=%d',array('jamesonread_buytids',$_G['uid'],$tid))){
            echo lang('plugin/jameson_read','yijinggoumaiguo');
        }else {
            if($_GET['autobuy']){
                dsetcookie('jamesonreadautobuy_'.$_G['uid'],1, 4800 * 3600);
            }
            if ($_G['jameson_read']['tramenum'] < $columinfo['price']) {
                $dizhi = '';
                if (checkmobile()) {
                    $dizhi = $_G['jameson_read']['sjchongzhi'] ? $_G['jameson_read']['sjchongzhi'] : $dizhi;
                } else {
                    $dizhi = $_G['jameson_read']['pcchongzhi'] ? $_G['jameson_read']['pcchongzhi'] : $dizhi;
                }
                echo 'chongzhi';
            } else {
                if (!C::t('#jameson_read#jamesonread_buytids')->sellaction($_G['uid'], $columinfo['uid'], $columinfo['price'], $tid, $columinfo['book_id'], $columinfo['category_id'], $_G['jameson_read']['trameid'], $_G['jameson_read']['yongjin'])) {
                    echo lang('plugin/jameson_read', 'kouchushibai');
                } else {
                    $yongjin       = floor($columinfo['price'] * ($_G['jameson_read']['yongjin']/ 100) );
                    $koufeimessage = lang('plugin/jameson_read', 'goumaichenggong') . ',' . lang('plugin/jameson_read', 'yikouchu') . $columinfo['price'] . $_G['jameson_read']['trametitle'];
                    $sendauthor    = '<a href="./home.php?mod=space&uid='
                    . $_G['uid']
                    . '">'
                    . $_G['member']['username']
                    . '</a>'
                    . lang('plugin/jameson_read', 'goumailenidetushu')
                    . lang('plugin/jameson_read', 'zhangjie')
                    . '<a href="'
                    . ($_G['cache']['plugin']['jameson_read']['rewurl'] ? jamesonurl('thread', $columinfo['tid'], $columinfo['pid']) : './plugin.php?id=jameson_read&contrl=index&act=read&tid=' . $columinfo['tid'] . '&pid=' . $columinfo['pid'])
                    . '">['
                    . $columinfo['subject']
                    . ']</a>,'
                    . lang('plugin/jameson_read', 'kouchuyongjinhoushouru')
                        . ($columinfo['price'] - $yongjin)
                        . $_G['jameson_read']['trametitle'];

                    $sendbuy =
                    lang('plugin/jameson_read', 'nichenggonggoumaizhangjie')
                    . '<a href="'
                    . ($_G['cache']['plugin']['jameson_read']['rewurl'] ? jamesonurl('thread', $columinfo['tid'], $columinfo['pid']) : './plugin.php?id=jameson_read&contrl=index&act=read&tid=' . $columinfo['tid'] . '&pid=' . $columinfo['pid'])
                    . '">['
                    . $columinfo['subject']
                    . ']</a>,'
                    . lang('plugin/jameson_read', 'yikouchu')
                        . $columinfo['price']
                        . $_G['jameson_read']['trametitle'];
                    // 向作者发送消息
                    jameson_sendsms($columinfo['uid'], 0, '', $sendauthor, $columinfo['colum_id']);
                    // 向购买者发送消息
                    jameson_sendsms($_G['uid'], 0, '', $sendbuy, $columinfo['colum_id']);
                    echo $koufeimessage;
                }
            }
        }
    }
    public function autobuy($columinfo)
    {
        global $_G;
        if (!$_G['uid']) {
            showmessage(lang('plugin/jameson_read', 'bixudenglu'), null, array(), array('showmsg' => true, 'login' => 1));
        }
        
            if ($_G['jameson_read']['tramenum'] < $columinfo['price']) {
                $dizhi = '';
                if (checkmobile()) {
                    $dizhi = $_G['jameson_read']['sjchongzhi'] ? $_G['jameson_read']['sjchongzhi'] : $dizhi;
                } else {
                    $dizhi = $_G['jameson_read']['pcchongzhi'] ? $_G['jameson_read']['pcchongzhi'] : $dizhi;
                }
                showmessage($dizhi?($_G['jameson_read']['trametitle'] . lang('plugin/jameson_read', 'buzuqingchongzhi')):lang('plugin/jameson_read','buzhichishoujiduan'), $dizhi);
            } else {
                if (!C::t('#jameson_read#jamesonread_buytids')->sellaction($_G['uid'], $columinfo['uid'], $columinfo['price'], $columinfo['tid'], $columinfo['book_id'], $columinfo['category_id'], $_G['jameson_read']['trameid'], $_G['jameson_read']['yongjin'])) {
                    return false;
                } else {
                    $yongjin       = floor($columinfo['price'] * ($_G['jameson_read']['yongjin'] / 100));
                    $koufeimessage = lang('plugin/jameson_read', 'goumaichenggong') . ',' . lang('plugin/jameson_read', 'yikouchu') . $columinfo['price'] . $_G['jameson_read']['trametitle'];
                    $sendauthor    = '<a href="./home.php?mod=space&uid='
                    . $_G['uid']
                    . '">'
                    . $_G['member']['username']
                    . '</a>'
                    . lang('plugin/jameson_read', 'goumailenidetushu')
                    . lang('plugin/jameson_read', 'zhangjie')
                    . '<a href="'
                    . ($_G['cache']['plugin']['jameson_read']['rewurl'] ? jamesonurl('thread', $columinfo['tid'], $columinfo['pid']) : './plugin.php?id=jameson_read&contrl=index&act=read&tid=' . $columinfo['tid'] . '&pid=' . $columinfo['pid'])
                    . '">['
                    . $columinfo['subject']
                    . ']</a>,'
                    . lang('plugin/jameson_read', 'kouchuyongjinhoushouru')
                        . ($columinfo['price'] - $yongjin)
                        . $_G['jameson_read']['trametitle'];

                    $sendbuy =
                    lang('plugin/jameson_read', 'nichenggonggoumaizhangjie')
                    . '<a href="'
                    . ($_G['cache']['plugin']['jameson_read']['rewurl'] ? jamesonurl('thread', $columinfo['tid'], $columinfo['pid']) : './plugin.php?id=jameson_read&contrl=index&act=read&tid=' . $columinfo['tid'] . '&pid=' . $columinfo['pid'])
                    . '">['
                    . $columinfo['subject']
                    . ']</a>,'
                    . lang('plugin/jameson_read', 'yikouchu')
                        . $columinfo['price']
                        . $_G['jameson_read']['trametitle'];
                    // 向作者发送消息
                    jameson_sendsms($columinfo['uid'], 0, '', $sendauthor, $columinfo['colum_id']);
                    // 向购买者发送消息
                    jameson_sendsms($_G['uid'], 0, '', $sendbuy, $columinfo['colum_id']);
                    return true;
                }
            }
    }
    function plbuytid(){
        global $_G;
        if(FORMHASH != $_GET['formhash']){
            showmessage(lang('plugin/jameson_read', 'laiyuanfeifa'), dreferer());
        }else{
            $bookinfo = C::t('#jameson_read#jamesonread_books')->fetch($_GET['book_id']);
            $tids = explode(',',$_GET['tidhidden']);
            $tidprice = explode(',',$_GET['tidpricehidden']);
            $total = 0;
            foreach ($tidprice as $money) {
                $total += intval($money);
            }
            if ($_G['jameson_read']['tramenum'] < $total) {
                $dizhi = '';
                if (checkmobile()) {
                    $dizhi = $_G['jameson_read']['sjchongzhi'] ? $_G['jameson_read']['sjchongzhi'] : $dizhi;
                } else {
                    $dizhi = $_G['jameson_read']['pcchongzhi'] ? $_G['jameson_read']['pcchongzhi'] : $dizhi;
                }
                showmessage($dizhi?($_G['jameson_read']['trametitle'] . lang('plugin/jameson_read', 'buzuqingchongzhi')):lang('plugin/jameson_read','buzhichishoujiduan'), $dizhi);
            }
            foreach ($tids as $k => $tid) {
                C::t('#jameson_read#jamesonread_buytids')->insert(
                    array(
                        'buy_id'=>$_G['uid'],
                        'tid'=>$tid,
                        'author_id'=>$bookinfo['uid'],
                        'category_id'=>$bookinfo['category_id'],
                        'addtime'=>TIMESTAMP,
                        'price'=>intval($tidprice[$k]),
                        'book_id'=>intval($_GET['book_id'])
                    )
                );
                
                $yongjin       = floor(intval($tidprice[$k]) * ($_G['jameson_read']['yongjin'] / 100));
                // 购买者减去 total
                $res1 = updatemembercount($_G['uid'],
                    array($_G['jameson_read']['trameid'] => -intval($tidprice[$k])),
                    true, 'jgm', 0, lang('plugin/jameson_read', 'goumaitushufeiyong'), daddslashes($bookinfo['book_name']));
                // 作者增加 total-yongji
                $res2 = updatemembercount($bookinfo['uid'],
                    array($_G['jameson_read']['trameid'] => (intval($tidprice[$k]) - $yongjin)),
                    true, 'jxs', 0, lang('plugin/jameson_read', 'xiaoshoutushufeiyong'), daddslashes($bookinfo['book_name']));
                // admin增加 yongji
                if($yongjin>0){ 
                    $res3 = updatemembercount(1,
                    array($_G['jameson_read']['trameid'] => $yongjin),
                    true, 'Y_J', 0, lang('plugin/jameson_read', 'xiaoshouyongjin'), daddslashes($bookinfo['book_name']));
                }
                DB::insert('jamesonread_yongjin', array(
                    'buy_id'    => $_G['uid'],
                    'author_id' => $bookinfo['uid'],
                    'book_id'   => intval($_GET['book_id']),
                    'saleprice' => intval($tidprice[$k]),
                    'yongjinbi' => $_G['jameson_read']['yongjin'],
                    'yongjin'   => $yongjin,
                    'type'      => 1,
                    'addtime'   => TIMESTAMP,
                ));
                $koufeimessage = lang('plugin/jameson_read', 'goumaichenggong') 
                . ',' 
                . lang('plugin/jameson_read', 'yikouchu') 
                . $total 
                . $_G['jameson_read']['trametitle'];
                
                $sendauthor    = '<a href="./home.php?mod=space&uid='
                . $_G['uid']
                . '">'
                . $_G['member']['username']
                . '</a>'
                . lang('plugin/jameson_read', 'goumailenidetushu')
                . lang('plugin/jameson_read', 'zhangjie')
                . '['
                .($k+1)
                .']<a href="./plugin.php?id=jameson_read&contrl=index&act=book&book_id='.$bookinfo['book_id'].'">'.$bookinfo['book_name'].'</a>,'
                . lang('plugin/jameson_read', 'kouchuyongjinhoushouru')
                . ($total - $yongjin)
                . $_G['jameson_read']['trametitle'];

                $sendbuy =
                lang('plugin/jameson_read', 'nichenggonggoumaizhangjie')
                . '['
                .($k+1)
                .']<a href="./plugin.php?id=jameson_read&contrl=index&act=book&book_id='.$bookinfo['book_id'].'">'.$bookinfo['book_name'].'</a>,'
                . lang('plugin/jameson_read', 'yikouchu')
                . $total
                . $_G['jameson_read']['trametitle'];
                // 向作者发送消息
                jameson_sendsms($bookinfo['uid'], 0, '', $sendauthor, $bookinfo['book_id']);
                // 向购买者发送消息
                jameson_sendsms($_G['uid'], 0, '', $sendbuy, $bookinfo['book_id']);
                // 
            }
            
            header('Cache-control:no-cache,no-store,must-revalidate');
            header('Pragma:no-cache');
            header('Expires:0');
            showmessage($koufeimessage, dreferer(), array(), array('showmsg' => true, 'alert' => 'right'));
        }
    }
    protected function is_weixin()
    {
        if (stripos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
            return 1;
        }
        return 0;
    }
    protected function is_utf8($str)
    {
        return xfxs_isutf($str);
    }
}